/*
 * @FilePath: /tads/server/app/business/service/dto/icon.go
 * @Author: wnina0x0
 * @Date: 2025-04-18 09:35:31
 * @Description:
 *
 * 版权信息 : 2025 by wnina0x0, All Rights Reserved.
 */
package dto

import (
	"tads/server/app/business/models"
	"time"
)

type IconGetRequests struct {
	GetPage
	ID       uint   `form:"id"`
	IconName string `form:"icon_name"`
}

type IconInsetRequests struct {
	IconName         string `form:"icon_name"`
	IconBusType      string `form:"icon_bus_type"`
	IconAttackMethod string `form:"icon_attack_method"`
}

func (i *IconInsetRequests) Generate(models *models.Icon, icon_path string, icon_attack_path string) {
	models.IconName = i.IconName
	models.IconPath = icon_path
	models.IconAttackPath = icon_attack_path
	models.IconBusType = i.IconBusType
	models.IconAttackMethod = i.IconAttackMethod
	models.Creator = "admin"
	models.CreateTime = time.Now()
	models.Updater = "admin"
	models.UpdateTime = time.Now()
}

type IconUpdateRequests struct {
	ID               uint   `json:"id"`
	IconName         string `json:"icon_name"`
	IconBusType      string `json:"icon_bus_type"`
	IconAttackMethod string `json:"icon_attack_method"`
}

func (i *IconUpdateRequests) Generate(models *models.Icon, icon_path string, icon_attack_path string) {
	models.IconName = i.IconName
	models.IconPath = icon_path
	models.IconAttackPath = icon_attack_path
	models.IconBusType = i.IconBusType
	models.IconAttackMethod = i.IconAttackMethod
	models.Updater = "admin"
	models.UpdateTime = time.Now()
}

type IconStatusRequests struct {
	ID     uint `json:"id"`
	Status bool `json:"status"`
}

type IconGetResponse struct {
	Total       int           `json:"total"`        // 总记录数
	TotalPages  int           `json:"total_pages"`  // 总页数
	CurrentPage int           `json:"current_page"` // 当前页
	PageSize    int           `json:"page_size"`    // 每页数量
	Data        []models.Icon `json:"data"`         // 实际数据
}

func (p *IconGetResponse) NewPageResponse(total int, req *IconGetRequests, data []models.Icon) *IconGetResponse {
	totalPages := total / req.PageSize
	if total%req.PageSize > 0 {
		totalPages++
	}

	return &IconGetResponse{
		Total:       total,
		TotalPages:  totalPages,
		CurrentPage: req.PageIndex,
		PageSize:    req.PageSize,
		Data:        data,
	}
}
